package com.hanrui.android.fragment.message.audit.proposal;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.model.ProposalVoteDetailBean;
import com.hanrui.android.net.contract.message.audit.proposal.ProposalVoteDetailContract;
import com.hanrui.android.net.presenter.message.audit.proposal.ProposalVoteDetailPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 董事会表决审批基本信息
 *
 */

public class ProposalVoteDetailFragment extends BaseFragment<ProposalVoteDetailPresenter> implements ProposalVoteDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.notice)
    TextView notice;
    @BindView(R.id.remark)
    TextView remark;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;


    String taskId,procInsId,bizId;

    List<FilesBean> filesBeanList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_proposalvotedetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.proposalVoteBizDetail(getActivity(),taskId,procInsId,bizId);

    }

    @OnClick({R.id.enclosure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.enclosure:
                MyDownLoadActivity.start(getActivity(),filesBeanList);
                break;
        }
    }

    public static ProposalVoteDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        ProposalVoteDetailFragment fragment = new ProposalVoteDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void proposalVoteBizDetail(ProposalVoteDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getName()+"的董事会审批");
            subheadTitle.setText(data.getDetail().getWarningDate());
            name.setText(data.getDetail().getTypeName());
            thingTitle.setText(data.getDetail().getName());
            time.setText(data.getDetail().getWarningDate());
            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                enclosureNum.setText("["+data.getFiles().size()+"]");
                filesBeanList.clear();
                filesBeanList.addAll(data.getFiles());

            		}
            dutyPeople.setText(data.getDetail().getMeetingLeader());
            notice.setText(data.getDetail().getNoticeMessage());
            remark.setText(data.getDetail().getRemarks());

            if (null != data.getDetail().getProposal() && data.getDetail().getProposal().size() > 0) {

                for (int i = 0; i < data.getDetail().getProposal().size(); i++) {

                    addViewItem(data.getDetail().getProposal().get(i));

                }

                return;

            }

            lladdview.setVisibility(View.GONE);

        }

    }


    //添加ViewItem
    private void addViewItem(final ProposalVoteDetailBean.DetailBean.ProposalBean bean) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_proposalvote, null);
        TextView billName = hotelEvaluateView.findViewById(R.id.bill_name);
        TextView billCompany = hotelEvaluateView.findViewById(R.id.bill_company);
        TextView billUser = hotelEvaluateView.findViewById(R.id.bill_user);
        ImageView enclosure = hotelEvaluateView.findViewById(R.id.enclosure);
        TextView enclosureNum = hotelEvaluateView.findViewById(R.id.enclosure_num);

        billName.setText(bean.getProposal());
        billCompany.setText(bean.getShowOfficeName());
        billUser.setText(bean.getName());
        enclosureNum.setText("["+bean.getFile().size()+"]");

        enclosure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                MyDownLoadActivity.start(getActivity(),bean.getFile());

            }
        });


        lladdview.addView(hotelEvaluateView);
    }

}
